package face.yuque;


/**
 * @author spf
 * @date 2024/12/10
 * @time 23:18
 */

// 方法二：埃筛法
public class PrimeCount2 {
    public static void main(String[] args) {
        System.out.println(countPrimes(100));
    }

    private static int countPrimes(int n) {
        if (n < 2) return 0;
        boolean[] isPrime = new boolean[n];
        int count = 0;
        for (int i = 2; i < n; i++) {
            if (!isPrime[i]) {
                count++;
                for (int j = i * i; j < n; j += i) {
                    isPrime[j] = true;
                }
            }
        }
        return count;
    }
}
